/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package physical_spaces.business;

import Entity.ControlFile;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import physical_spaces.DAO.ListControlFileDAO;

/**
 *
 * @author JuanSebastian
 */
public class ListControlFileBusiness {
    
    private ArrayList<ControlFile> controlFiles;
    public Connection conn;   

    public ListControlFileBusiness(Connection conn ) {
          this.conn=conn;
          
    }
    
    public ArrayList<ControlFile> listControlFiles() {
       this.controlFiles = new ArrayList<>();  
        
       String sql= "SELECT NAME FROM V$CONTROLFILE"; 
       
       try{
            ResultSet rs = new ListControlFileDAO(conn).executeStatement( sql );
            
            while( rs.next() ){
                ArrayList<String> stringList = new ArrayList<>();
                for(int i = 1 ; i <= rs.getMetaData().getColumnCount() ; i++){
                    stringList.add( rs.getString(i) );
                    
                }
                                
                controlFiles.add( new ControlFile( stringList.get(0)));
                
            }
        } catch ( SQLException | NumberFormatException e ){
             FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_WARN,
                    "Error de Consulta!",
                    "Please Try Again! " + e.getMessage()));
        }
        
        return controlFiles;
                
    }
    
}
